package studyNote;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

public class SetDemo {
    public static void main(String[] args) {
        // 自定义顺序
        TreeSet<String> set = new TreeSet<>(new Comparator<>() {
            @Override
            public int compare(String s1, String s2) {
                // 按你想要的顺序定义
                String[] order = {"及格", "良好", "优秀"};
                int index1 = getIndex(s1, order);
                int index2 = getIndex(s2, order);
                return Integer.compare(index2, index1);
            }

            private int getIndex(String s, String[] order) {
                for (int i = 0; i < order.length; i++) {
                    if (order[i].equals(s)) return i;
                }
                return -1;
            }
        });

        set.add("优秀");
        set.add("良好");
        set.add("及格");
        set.add("上等");

        System.out.print("自定义排序:");
        for (String s : set) {
            System.out.print(s + " ");
        }
        System.out.println();
        SortedSet<String> subSet = set.tailSet("良好");
        for (String s : subSet) {
            System.out.println(s);
        }
    }
}